import userPageApi from '@/api/user/userPageApi'
import OptionProps from '@/model/other/OptionProps'
import { useEffect, useState } from 'react'

// 获取所有用户列表
export default function useEffectUserPage(
  noLoading: boolean,
  addAdminFlag?: boolean
) {
  const [userList, setUserList] = useState<OptionProps[]>([])

  useEffect(() => {
    if (!noLoading) {
      userPageApi({
        pageSize: -1,
        addAdminFlag,
        orderList: [{ name: 'a.update_time', value: 'descend' }], // 在排序最后追加根据更新时间倒序
      }).then(({ data }) => {
        setUserList(
          data.data.records.map((item) => ({
            label: item.nickname,
            value: item.id,
          })) as OptionProps[]
        )
      })
    }
  }, [noLoading])

  return { userList }
}
